package com.example.demo.practice.ui;

import android.content.Context;

import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

/**
 * Created by hanbo on 2018-01-05.
 */

public class LineView extends LinearLayout{

    public LineView(Context context) {
        super(context);
        View line = new View(context);
        line.setBackgroundColor(StringToColor("#1f2641"));
        //添加横线
        ViewGroup.LayoutParams lineParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1);
        addView(line, lineParams);

    }

    public LineView(Context context, AttributeSet attrs) {
        super(context, attrs);
        View line = new View(context);
        line.setBackgroundColor(StringToColor("#1f2641"));
        //添加横线
        ViewGroup.LayoutParams lineParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1);
        addView(line, lineParams);
    }

    public LineView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        View line = new View(context);
        line.setBackgroundColor(StringToColor("#1f2641"));
        //添加横线
        ViewGroup.LayoutParams lineParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1);
        addView(line, lineParams);
    }


    /**
     * #颜色转16进制颜色
     *
     * @param str {String} 颜色
     * @return
     */
    private int StringToColor(String str) {
        return 0xff000000 | Integer.parseInt(str.substring(2), 16);
    }
}
